<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddPublishTimeInVersionTable extends AbstractMigration
{
    public function up()
    {
        $this->table('version')
            ->addColumn('published', 'integer', [
                'signed' => false,
                'default' => 0,
                'limit' => 11,
                'comment' => '发布时间',
            ])->save();

        $this->execute("update version set published = if(updated>0,updated,created) where is_publish = 'yes' and published = 0 ");
    }

    public function down()
    {
        $this->table('version')
            ->removeColumn('published')
            ->save();
    }

}
